package com.sfx.concurrent.demo.concurrent.ReentrantLock.condition;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: sfx
 * Date: 2023-01-09
 * Time: 18:18
 */

@Slf4j(topic = "c.TestDemo1")
public class TestDemo1 {
    static ReentrantLock lock = new ReentrantLock();
    public static void main(String[] args) throws InterruptedException {
        //要想进入条件变量(消息室) 必须获取到锁
        lock.lock();
        //一个锁对象可以由多个条件变量(多个休息室) 将其细分
        Condition condition1 = lock.newCondition();
        Condition condition2 = lock.newCondition();
        try{
            //去休息室1 里面等待
            condition1.await();

        }finally {
            lock.unlock();
        }
        //唤醒条件变量1(休息室1)的线程
        condition1.signal();
        //唤醒条件变量2(休息室2)所有的线程
        condition1.signalAll();
    }
}